Skip to content

Host core: a renderer pane's lifecycle as an explicit machine - #147

Merged
agorischek merged 3 commits into
mainfrom
pane-machine
Nov 21, 2026
Merged

agorischek merged 3 commits into
mainfrom
pane-machine

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

Stacked on #145. This is step 2 of the projection store (G4), following docs/design/proposals/headless-store.md.

Why

A renderer pane's state was a useState in RendererPane, updated by a switch over the frame's events. Its lifecycle was implicit:

  • nothing stopped a late event from moving a failed pane, which the frame's own lifecycle treats as final;
  • "ready" was whatever the last setState left.

The state-machine survey listed it (pane status aggregation, #16), and the store needs it framework-free.

What changed

  • src/pane-lifecycle.ts defines paneLifecycle with @githubnext/projections-machine:
    • States:
      • loading until the frame is revealed, then ready;
      • failed (with its message), which is final, as FrameLifecycle is, until reloaded (a new bundle) starts the pane over.
    • Reports: each state keeps what the renderer reported (capabilities, controls, steps, legend, summary, errors and the rest). reinit (a new document) drops what was painted and stepped for the old one. An unchanged report returns the same state, so nothing re-renders.
    • paneStateOf gives the public PaneState, which is unchanged.
  • RendererPane runs it with useMachine. The actor starts in a layout effect, before the frame (created in an effect) can send anything, and its changes render as setState did. Callback-only events (select, hover, anchor and the rest) are unchanged.
  • The Inspector's snapshot readiness uses the core's paintState in place of its private painted. They're equivalent for the progress it controls, and paintState also ignores an acknowledgement of an earlier document (Host core: tell hosts when the renderer is ready and when the frames have painted #122). SnapshotState.keys goes.

Not here, and why

The design had #122's events (onRendererStatusChange and onPainted) as this machine's effects. They depend on every shown pane, not one, so they stay derived from rendererStatus and paint until the store composes the panes (step 4), where they become its effects with the same names. The design note's step 2 now says this.

Tests

packages/host/core/test/pane-lifecycle.test.mjs:

  • explore with complete: true: every listed handler is reachable. Its invariants:

    • only a failed pane has a message;
    • at most five errors are kept;
    • a painted progress always names its document.

    Its transition properties:

    • failed is left only on reloaded;
    • ready is entered only on revealed.
  • A walk through the public PaneState: status, failure, reinit, an unchanged report keeping identity, and the reset on reload.

Run locally:

  • tools check --fast: pass, with the machines gate and no baseline change.
  • tsc for core: pass. The Inspector's snapshot files have no errors; the rest of its build needs renderers that aren't built here.
  • node --test on pane-lifecycle, settings-store, paint, playback-lifecycle, host and frame-reopen: 29/29.

The browser suites run in CI.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Snapshot readiness can accept stale render acknowledgements or snapped progress, producing captures before the new document is painted or at the wrong revision.

3 open issues
What changed in this PR

This PR extracts renderer-pane lifecycle rules from React as the next step toward the headless projection store, while preserving the public PaneState shape.

Changes:

  • Adds an explicit pane lifecycle machine and tests for transitions, invariants and resets.
  • Integrates useMachine into RendererPane and reuses core paintState for Inspector snapshot readiness.
  • Updates the store plan to defer aggregate status effects until pane composition.
File Description
packages/​host/​inspector/​src/​snapshot/​readiness.ts Replaces the private painted check with core paintState.
packages/​host/​inspector/​src/​snapshot/​page.tsx Removes obsolete pane keys from the readiness input.
packages/​host/​core/​test/​pane-lifecycle.test.mjs Tests lifecycle transitions, invariants and public state.
packages/​host/​core/​src/​pane.tsx Replaces inline state updates with the lifecycle machine.
packages/​host/​core/​src/​pane-lifecycle.ts Defines pane stages, report handling and reset rules.
docs/​design/​proposals/​headless-store.md Clarifies step 2 and the timing of aggregate status effects.

Review effort: Balanced

Comment thread packages/host/core/src/pane.tsx Resolved
Base automatically changed from projection-store to main November 21, 2026 17:27
The second step of the projection store (docs/design/proposals/headless-store.md). A pane's state was a `useState`
updated by a switch over its frame's events. It is now `paneLifecycle`, defined with the machine package: loading
until the frame is revealed, then ready; failed for good, as the frame itself is, until a new bundle loads; each state
keeps what the renderer reported, and a new document drops what was painted and stepped for the old one.
`RendererPane` runs it with `useMachine`, and `PaneState` is unchanged. The Inspector's snapshot page now judges paint
with the core's `paintState`, which also ignores an acknowledgement of an earlier document.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
agorischek and others added 2 commits November 21, 2026 09:36
… the progress they asked for

The pane lifecycle compares reported values, not the new copy each report
arrives in, so a repeated report changes nothing; the painted init is compared
by identity. The Inspector's snapshot readiness passes its requested progress
to paintState, as it compared before, since a step can snap the controller's.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@agorischek
agorischek merged commit 6955cdb into main Nov 21, 2026
46 checks passed
@agorischek
agorischek deleted the pane-machine branch November 21, 2026 19:18
agorischek added a commit that referenced this pull request Nov 21, 2026
…ge last showed (#153)

* Renderer test helpers: bound each stage request, and say what the stage last showed

A stage the renderer harness drives through openStage could stop answering:
WebKit runs the sandboxed renderer frame in the host page's process, so a
renderer stuck in its document stops the stage page with it, and the page's
own waits (a probe measurement's 10 s, a frame's arrival at 60 s) never fire.
diff.spec's graph test then waited the whole 360 s test timeout on a
measure('settle'), or on a locator in the frame, twice on #147.

Each request a StageHandle makes of the page (load, seek, measure, state, …)
now fails after 90 s in the test process, naming the request, the scenario
and the stage's last known state (status, renderer, mode, progress painted,
height asked for, errors) and when the page last answered. The page's own
bounds stay where they were; this one only catches a page that no longer
runs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Renderer test helpers: an unanswered stage request names both of its causes

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants